{% extends "FOSUserBundle::layout.html.twig" %}
{% block head %}
{{parent()}}
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") == false %}
	<meta http-equiv="refresh" content="1; url={{path('fos_user_security_login')}}" />
	<script type="text/javascript">
            window.location.href = "{{ path('fos_user_security_login') }}"
    </script>
{% endif %}
{% endblock head %}

{% block fos_user_content %}
	{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
    
        {% for flashMessage in app.session.flashbag.get('message') %}
        <div class="toast">
            {{ flashMessage }}<img src="{{ asset('img/close.png') }}" witdh="16" height="16" onclick="this.parentNode.style.display='none'"/>
        </div>
        {% endfor %}
        
        <div id="dragme" class="login unselectable hidden"></div>
		
		<menu>
	<ul>
		<li><a href="{{path('cadss_test_homepage')}}">Documents</a></li>
		<li>
			{{ form_start(form) }}
			{{ form_widget(form.searchterm) }}
			{{ form_widget(form.search) }}
			{{ form_end(form) }}
			<!--<form id="form_search" method="post" action="">
				<input type="text" class="searchfield" name="search" />
				<input type="submit" value="search" class="searchbutton" />
			</form>-->
		</li>
		<li><a onclick="openPopUp('{{ path('cadss_test_upload') }}');">Upload Document</a></li>
		<li><a href="{{ path('cadss_test_keywords') }}">Manage Keywords</a></li>
		<li><a href="{{ path('fos_user_security_logout') }}">{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}</a></li>
	</ul>
</menu>
<br />
<br />
<div id="files">
	{% if files_with_keyword is defined %}
	<table>
		<tr>
			<th width="920">Keyword: {{ keyword.keyword }}</th>
			<th width="80"><a onclick="openPopUp('{{ path('cadss_test_edit_keyword', {'id': keyword.id}) }}');"><img src="{{ asset('img/edit.png') }}" title="edit" alt="edit" width="15" height="15"/></a><a href="{{ path('cadss_test_delete_keyword', {'id': keyword.id}) }}"><img src="{{ asset('img/delete.png') }}" title="delete" alt="delete" width="15" height="15"/></a>
			</th>
		</tr>
	</table>
	{% endif %}
	<br />
	<table>
		<tr>
			<th width="100">Title</th>
			<th width="300">Description</th>
			<th width="300">Keywords</th>
			<th width="100">Uploader</th>
			<th width="110">Upload date</th>
			<th width="100"></th>
		</tr>
		{% if files_with_keyword is defined %}
			{% for file in keyword.documents %}
				<tr>
					<td>{{ file.dTitel }}</td>
					<td>{{ file.dOmschrijving }}</td>
					<td>
						{% for keyword in file.keywords %}
							{% if loop.last %}
								{{keyword.keyword}} 
							{% else %}
								{{keyword.keyword}},
							{% endif %}
						{% endfor %}
					</td>
					<td>{{ file.User.username }}</td>
					<td>{{ file.dDatum|date('d-m-Y') }}</td>
					<td>
						<a href="{{ asset('uploads/documents/') }}{{ file.path }}">
							<img src="{{ asset('img/download.png') }}" title="download" alt="download" width="15" height="15"/>
						</a>
						{% if file.dUid == app.security.getToken().getUser().getId()  %}
							<a onclick="openPopUp('{{ path('cadss_test_edit_document', {'id': file.id}) }}');">
								<img src="{{ asset('img/edit.png') }}" title="edit" alt="edit" width="15" height="15"/>
							</a>
							<a href="{{ path('cadss_test_delete_document', {'id': file.id}) }}">
								<img src="{{ asset('img/delete.png') }}" title="delete" alt="delete" width="15" height="15"/>
							</a>
						{% endif %}
					</td>
				</tr>
			{% endfor %}
		{% endif %}
		{% if files is defined %}
			{% for file in files %}
			<tr>
				<td>{{ file.dTitel }}</td>	
				<td>{{ file.dOmschrijving }}</td>
				<td>
					{% for keyword in file.keywords %}
						{% if loop.last %}
							{{keyword.keyword}} 
						{% else %}
							{{keyword.keyword}},
						{% endif %}
					{% endfor %}
				</td>
				<td>{{ file.User.username }}</td>
				<td>{{ file.dDatum|date('d-m-Y') }}</td>
				<td>
					<a href="{{ asset('uploads/documents/') }}{{ file.path }}"><img src="{{ asset('img/download.png') }}" title="download" alt="download" width="12" height="12"/></a>
					{% if file.dUid == app.security.getToken().getUser().getId()  %}
						<a onclick="openPopUp('{{ path('cadss_test_edit_document', {'id': file.id}) }}');"><img src="{{ asset('img/edit.png') }}" title="edit" alt="edit" width="12" height="12"/></a>
						<a href="{{ path('cadss_test_delete_document', {'id': file.id}) }}"><img src="{{ asset('img/delete.png') }}" title="delete" alt="delete" width="12" height="12"/></a>
					{% endif %}
				</td>
			</tr>
			{% endfor %}
		{% endif %}
	</table>
</div>
    {% endif %}
{% endblock fos_user_content %}